package org.kabeja.parser.table;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.entity.DXFView;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 14:17
 */
public class DXFViewTableHandler extends AbstractTableHandler {
    public static final int GROUPCODE_NAME = 2;
    public static final int GROUPCODE_CENTER_X = 10;
    public static final int GROUPCODE_CENTER_Y = 20;
    public static final int GROUPCODE_CENTER_Z = 30;
    public static final int GROUPCODE_HEIGHT = 40;
    public static final int GROUPCODE_WIDTH = 41;
    public static final int GROUPCODE_VIEW_DIRECTION_X = 11;
    public static final int GROUPCODE_VIEW_DIRECTION_Y = 21;
    public static final int GROUPCODE_VIEW_DIRECTION_Z = 31;
    public static final int GROUPCODE_VIEW_TARGET_X = 12;
    public static final int GROUPCODE_VIEW_TARGET_Y = 22;
    public static final int GROUPCODE_VIEW_TARGET_Z = 32;
    public static final int GROUPCODE_LENS_LENGTH = 42;
    public static final int GROUPCODE_FRONT_CLIPPING = 43;
    public static final int GROUPCODE_BACK_CLIPPING = 44;
    public static final int GROUPCODE_TWIST_ANGLE = 50;
    public static final int GROUPCODE_RENDER_MODE = 281;
    public static final int GROUPCODE_UCS_ORIGIN_X = 110;
    public static final int GROUPCODE_UCS_ORIGIN_Y = 120;
    public static final int GROUPCODE_UCS_ORIGIN_Z = 130;
    public static final int GROUPCODE_UCS_X_AXIS_X = 111;
    public static final int GROUPCODE_UCS_X_AXIS_Y = 121;
    public static final int GROUPCODE_UCS_X_AXIS_Z = 131;
    public static final int GROUPCODE_UCS_Y_AXIS_X = 112;
    public static final int GROUPCODE_UCS_Y_AXIS_Y = 122;
    public static final int GROUPCODE_UCS_Y_AXIS_Z = 132;
    public static final int GROUPCODE_UCS_TYPE = 79;
    public static final int GROUPCODE_UCS_ELEVATION = 146;
    public static final int GROUPCODE_USE_UCS = 72;
    private DXFView view;

    public DXFViewTableHandler() {
    }

    @Override
    public void endParsing() {
        this.doc.addDXFView(this.view);
    }

    @Override
    public String getTableKey() {
        return DXFConstants.TABLE_KEY_VIEW;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case GROUPCODE_NAME:
                this.view.setName(var2.getValue());
                break;
            case GROUPCODE_CENTER_X:
                this.view.getCenterPoint().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_CENTER_Y:
                this.view.getCenterPoint().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_CENTER_Z:
                this.view.getCenterPoint().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_HEIGHT:
                this.view.setHeight(var2.getDoubleValue());
                break;
            case GROUPCODE_WIDTH:
                this.view.setWidth(var2.getDoubleValue());
                break;
            case GROUPCODE_LENS_LENGTH:
                this.view.setLensLength(var2.getDoubleValue());
                break;
            case GROUPCODE_FRONT_CLIPPING:
                this.view.setFrontClipping(var2.getDoubleValue());
                break;
            case GROUPCODE_BACK_CLIPPING:
                this.view.setBackClipping(var2.getDoubleValue());
                break;
            case GROUPCODE_TWIST_ANGLE:
                this.view.setTwistAngle(var2.getDoubleValue());
                break;
            case GROUPCODE_USE_UCS:
                this.view.setUseUCS(var2.getBooleanValue());
                break;
            case GROUPCODE_UCS_TYPE:
                this.view.setUcsType(var2.getIntegerValue());
                break;
            case GROUPCODE_UCS_ORIGIN_X:
                this.view.getUcsOrigin().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_X_AXIS_X:
                this.view.getUcsXAxis().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_Y_AXIS_X:
                this.view.getUcsYAxis().setX(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_ORIGIN_Y:
                this.view.getUcsOrigin().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_X_AXIS_Y:
                this.view.getUcsXAxis().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_Y_AXIS_Y:
                this.view.getUcsYAxis().setY(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_ORIGIN_Z:
                this.view.getUcsOrigin().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_X_AXIS_Z:
                this.view.getUcsXAxis().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_Y_AXIS_Z:
                this.view.getUcsYAxis().setZ(var2.getDoubleValue());
                break;
            case GROUPCODE_UCS_ELEVATION:
                this.view.setUcsElevation(var2.getDoubleValue());
                break;
            case GROUPCODE_RENDER_MODE:
                this.view.setRenderMode(var2.getIntegerValue());
                break;
            default:
                break;
        }

    }

    @Override
    public void startParsing() {
        this.view = new DXFView();
    }
}
